/**
 * 
 */
package se.ricardo.gamesorgs.api.request;

/**
 * Class for storing the GUI options entered by the user.<br>
 * A GamesOptionsRequest is sent between the view and the model
 * by intermediate of the Controller.
 * <br>
 *  
 * @author Ricardo Ocaña Leal
 *
 */
public class GamesOptionsRequest extends AbstractRequest {
	private String previousCompany;
	private String previousSystem;
	private int companyIndex;
	private int systemsIndex;
	private boolean systemsUpdate;
	
	/**
	 * Initialize variables with default values.
	 * */
	public GamesOptionsRequest() {
		super();
		
		companyIndex = 0;
		systemsIndex = 0;
		previousCompany = "";
		previousSystem = "";
		systemsUpdate = false;
	}
	
	/**
	 * Sets the name of the selected company.
	 * 
	 * @param
	 * company A String with the name of the company.
	 * */
	@Override
	public void setCompany(String company) {
		previousCompany = getCompany();
		
		// If the company selection has changed, then
		// the gamesystems list should be updated.
		if(!previousCompany.equals(company)) {
			setSystemsUpdate(true);
			setSystemsIndex(0);
		}
		
		super.setCompany(company);
	}
	
	public void setCompanyIndex(int index) {
		companyIndex = index;
	}
	
	public int getCompanyIndex() {
		return companyIndex;
	}
	
	/**
	 * Sets the name of the selected system.
	 * <br>
	 * 
	 * @param
	 * system A String with the name of the system.
	 * */
	@Override
	public void setSystem(String system) {
		previousSystem = getSystem();
		super.setSystem(system);
	}
	
	/**
	 * Returns the previously selected company name.
	 * Used for the program to verify what should be updated.
	 * <br>
	 * 
	 * @return
	 * previousCompany The name of the company.
	 * */
	public String getPreviousCompany() {
		return previousCompany;
	}
	
	/**
	 * Returns the previously selected system name.
	 * Used for the program to verify what should be updated.
	 * <br>
	 * 
	 * @return
	 * previousSystem The name of the system.
	 * */
	public String getPreviousSystem() {
		return previousSystem;
	}
	
	/**
	 * Sets the currently selected system index.
	 * <br>
	 * 
	 * @param
	 * index int representing the systems index.
	 * */
	public void setSystemsIndex(int index) {
		systemsIndex = index;
	}
	
	/**
	 * Returns the systems index to set in the systems list.
	 * <br>
	 * 
	 * @return
	 * int representing the systems index.
	 * */
	public int getSystemsIndex() {
		return systemsIndex;
	}
	
	/**
	 * Checks if the list selection has changed from previous one.
	 * <br>
	 * 
	 * @param
	 * listType Integer representing the list.
	 * */
	@Override
	public void setListType(int listType) {
		// If the listtype has changed, then the tab
		// has changed and the gamesystemslist should be
		// updated.
		if(listType != getListType()) {
			setSystemsUpdate(true);
		}
		
		super.setListType(listType);
	}
		
	/**
	 * Returns a boolean value representing if the systems
	 * list should be updated.
	 * <br>
	 * 
	 * @return
	 * Boolean value representing gamesystems update.
	 * */
	public boolean shouldSystemsUpdate() {
		return systemsUpdate;
	}
	
	/**
	 * Called to set if the gamesystems list should be updated.
	 * <br>
	 * 
	 * @param
	 * b Boolean value representing gamesystems update.
	 * */
	public void setSystemsUpdate(boolean b) {
		systemsUpdate = b;
	}
}
